<template>
  <a-modal
    title="价格审核"
    :width="1200"
    :visible="visible"
    :confirmLoading="confirmLoading"
    @ok="handleSubmit"
    :okButtonProps="{ props: { disabled: disableSubmit } }"
    @cancel="handleCancel"
    cancelText="关闭"
    style="top: 20px"
  >
    <a-spin :spinning="confirmLoading">
      <a-form :form="form">
        <a-row :gutter="24">
          <a-col :md="8" :sm="24">
            <a-form-item :labelCol="labelCol" :wrapperCol="wrapperCol" label="请选择">
              <j-dict-select-tag
                v-decorator="['channelFlag', validatorRules.status]"
                @change="handleWarehouseFlag"
                :type="'radioButton'"
                :triggerChange="true"
                dictCode="channelProductApplyReview_status"
              />
            </a-form-item>
          </a-col>
        </a-row>
      </a-form>
    </a-spin>
  </a-modal>
</template>

<script>
import pick from "lodash.pick";
import {httpAction} from "@/api/manage";
import {getAction} from "@/api/manage";

export default {
  name: "ChannelProductApplyApproveModal",

  data() {
    return {
      visible: false,
      confirmLoading: false,
      disableSubmit: false,
      approveStatus:2,
      applyId:0,
      form: this.$form.createForm(this),
      validatorRules: {
        status: { rules: [{ required: true, message: "请选择状态!" }] },
      },
      labelCol: {
        xs: {span: 24},
        sm: {span: 8},
      },
      wrapperCol: {
        xs: {span: 24},
        sm: {span: 13},
      },
      type: 1,
      url: {
        approve: "/stm/stmChannelInfo/approve",
      },
      loading: false,
    };
  },
  computed: {},
  methods: {
    show(type,applyId) {
      this.visible = true;
      this.type = type;
      this.model = Object.assign({});
      this.$nextTick(() => {
        this.form.setFieldsValue(pick(this.model, "channelFlag"));
      });
      this.model.channelFlag =2;
      this.applyId=applyId;
    },
    close() {
      this.form.resetFields();
      this.$emit("close");
      this.visible = false;
    },
    handleSubmit() {
      console.log(11111)
      this.confirmLoading = true;
      if(this.type==1 && this.model.channelFlag == "2"){
        this.approveStatus=2;
      }
      else if(this.type==2 && this.model.channelFlag == "2"){
        this.approveStatus=3;
      }
      else {
        this.approveStatus=4;
      }
      let formData = {
        status: this.approveStatus,
        applyId:this.applyId
      };
      this.form.validateFields((err, values) => {
        if (!err) {
          getAction(this.url.approve, formData)
            .then((res) => {
              if (res.success) {
                this.$message.success(res.message);
                this.$emit("ok");
              } else {
                this.$message.warning(res.message);
              }
            })
            .finally(() => {
              this.confirmLoading = false;
              this.close();
            });
        }
      });
      this.confirmLoading = false;
    },
    handleCancel() {
      this.close();
    },
    handleWarehouseFlag(e) {
      this.model.channelFlag = e;
    },
  },
};
</script>
